package com.gitee.zycra.future.job.manager;

import com.gitee.zycra.future.job.common.bo.PageQuery;
import com.gitee.zycra.future.job.common.model.JobScheduleLog;
import com.gitee.zycra.future.job.common.param.PageQueryRunningParam;
import com.gitee.zycra.future.job.dao.JobScheduleLogDao;
import com.gitee.zycra.jdbc.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zycra
 */
@Component
public class JobScheduleLogManager {

    @Autowired
    private JobScheduleLogDao jobScheduleLogDao;

    /**
     * 批量插入执行日志
     *
     * @param jobScheduleLogList 执行日志集合
     * @return 插入条数
     */
    public int batchInsertJobScheduleLog(List<JobScheduleLog> jobScheduleLogList) {
        return jobScheduleLogDao.batchInsertJobScheduleLog(jobScheduleLogList);
    }

    /**
     * 根据任务调度ID查询
     *
     * @param pageQuery 查询参数
     * @return 查询到的数据
     */
    public PageResult<JobScheduleLog> selectJobScheduleLog(PageQuery<PageQueryRunningParam> pageQuery) {
        return jobScheduleLogDao.selectJobScheduleLog(pageQuery);
    }

    /**
     * 根据调度配置ID集合查询最近周期内完成的调度
     *
     * @param jobScheduleIdList 调度配置ID集合
     * @param startTime         起始时间
     * @return 完成的调度
     */
    public List<Long> selectSuccessByIdList(List<Long> jobScheduleIdList, LocalDateTime startTime) {
        return jobScheduleLogDao.selectSuccessByIdList(jobScheduleIdList, startTime);
    }
}
